<?php


namespace plugin\coleopenapi\app\logic;


use app\common\logic\BaseLogic;
use plugin\coleopenapi\app\model\OpenapiAppSign;
use core\utils\CacheUtil;

class AppSignLogic extends BaseLogic
{
    const APP_INFO = "openapi:app_info";

    public function __construct()
    {
        $this->model = new OpenapiAppSign();
    }

    public function getInfoByAppKey($appKey)
    {
        return CacheUtil::tag(self::APP_INFO)->remember(self::APP_INFO . ':' . $appKey, function () use ($appKey) {
            $data = $this->model->where('app_key', $appKey)->find();
            return $data ? $data->toArray() : [];
        }, 24 * 60 * 60);
    }

    public function removeCache()
    {
        return CacheUtil::tag(self::APP_INFO)->clear();
    }
}